package com.gsta.cdn.cdr.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.gsta.cdn.cdr.entity.ResultEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Mapper
@Component(value = "FileSizeMapper")
public interface FileSizeMapper extends BaseMapper<ResultEntity> {
    @Select("<script>" +
            " SELECT * FROM FileSizeAll  " +
            " WHERE Date LIKE CONCAT(#{Date},'%')  AND Percent=#{Percent} "+
            "ORDER BY Date " +
            "LIMIT #{page},#{pageSize} "+
            "</script>")
    List<Map<String, Object>> FileSizeAll(@Param("Date") String Date, @Param("Percent") String Percent, @Param("page") int page, @Param("pageSize") int pageSize);

    @Select("<script>" +
            "SELECT COUNT(*) AS count FROM ( " +
            " SELECT * FROM FileSizeAll  " +
            " WHERE Date LIKE CONCAT(#{Date},'%')  AND Percent=#{Percent})t  "+
            "</script>")
    int FileSizeAllCount (@Param("Date") String Date, @Param("Percent") String Percent);

    @Select("<script>" +
            " SELECT DISTINCT Area FROM FileSizeArea  " +
            " WHERE Date LIKE CONCAT(#{Date},'%')  AND Percent=#{Percent} "+
            "ORDER BY Area " +
            "</script>")
    List<Map<String, Object>> FileSizeArea(@Param("Date") String Date, @Param("Percent") String Percent);

    @Select("<script>" +
            " SELECT * FROM FileSizeArea  " +
            " WHERE Date LIKE CONCAT(#{Date},'%')  AND Percent=#{Percent} AND Area=#{Area} "+
            "ORDER BY Date " +
            "LIMIT #{page},#{pageSize} "+
            "</script>")
    List<Map<String, Object>> FileSizeByArea(@Param("Date") String Date, @Param("Percent") String Percent, @Param("Area") String Area,@Param("page") int page, @Param("pageSize") int pageSize);



    @Select("<script>" +
            "SELECT COUNT(*) AS count FROM ( " +
            " SELECT * FROM FileSizeArea  " +
            " WHERE Date LIKE CONCAT(#{Date},'%')  AND Percent=#{Percent} AND Area=#{Area})t  "+
            "</script>")
    int FileSizeByAreaCount (@Param("Date") String Date, @Param("Percent") String Percent,@Param("Area") String Area);

    @Select("<script>" +
            " SELECT * FROM FileSizePopName  " +
            " WHERE Date LIKE CONCAT(#{Date},'%')  AND Percent=#{Percent} AND PopName=#{PopName} "+
            "ORDER BY Date " +
            "LIMIT #{page},#{pageSize} "+
            "</script>")
    List<Map<String, Object>> FileSizeByPopName(@Param("Date") String Date, @Param("Percent") String Percent, @Param("PopName") String PopName,@Param("page") int page, @Param("pageSize") int pageSize);



    @Select("<script>" +
            "SELECT COUNT(*) AS count FROM ( " +
            " SELECT * FROM FileSizePopName  " +
            " WHERE Date LIKE CONCAT(#{Date},'%')  AND Percent=#{Percent} AND PopName=#{PopName})t  "+
            "</script>")
    int FileSizeByPopNameCount (@Param("Date") String Date, @Param("Percent") String Percent,@Param("PopName") String PopName);


    @Select("<script>" +
            " SELECT DISTINCT PopName FROM FileSizeAreaPopName  " +
            " WHERE Date LIKE CONCAT(#{Date},'%')  AND Percent=#{Percent} AND Area=#{Area} "+
            "ORDER BY PopName " +
            "</script>")
    List<Map<String, Object>> FileSizeAreaPopName(@Param("Date") String Date, @Param("Percent") String Percent,@Param("Area") String Area);

    @Select("<script>" +
            " SELECT * FROM FileSizeAreaPopName  " +
            " WHERE Date LIKE CONCAT(#{Date},'%')  AND Percent=#{Percent} AND Area=#{Area} AND PopName=#{PopName} "+
            "ORDER BY Date " +
            "LIMIT #{page},#{pageSize} "+
            "</script>")
    List<Map<String, Object>> FileSizeByAreaPopName(@Param("Date") String Date, @Param("Percent") String Percent, @Param("Area") String Area
            ,@Param("PopName") String PopName,@Param("page") int page, @Param("pageSize") int pageSize);

    @Select("<script>" +
            "SELECT COUNT(*) AS count FROM ( " +
            " SELECT * FROM FileSizeAreaPopName  " +
            " WHERE Date LIKE CONCAT(#{Date},'%')  AND Percent=#{Percent} AND Area=#{Area} AND PopName=#{PopName} )t  "+
            "</script>")
    int FileSizeByAreaPopNameCount (@Param("Date") String Date, @Param("Percent") String Percent,@Param("Area") String Area,@Param("PopName") String PopName);


    @Select("<script>" +
            " SELECT DISTINCT PopID FROM FileSizePopID  " +
            " WHERE Date LIKE CONCAT(#{Date},'%')  AND Percent=#{Percent} "+
            "ORDER BY RAND() LIMIT 30 " +
            "</script>")
    List<Map<String, Object>> FileSizePopID(@Param("Date") String Date, @Param("Percent") String Percent);

    @Select("<script>" +
            " SELECT * FROM FileSizePopID  " +
            " WHERE Date LIKE CONCAT(#{Date},'%')  AND Percent=#{Percent} AND PopID=#{PopID} "+
            "ORDER BY Date " +
            "LIMIT #{page},#{pageSize} "+
            "</script>")
    List<Map<String, Object>> FileSizeByPopID(@Param("Date") String Date, @Param("Percent") String Percent, @Param("PopID") String PopID,@Param("page") int page, @Param("pageSize") int pageSize);



    @Select("<script>" +
            "SELECT COUNT(*) AS count FROM ( " +
            " SELECT * FROM FileSizePopID  " +
            " WHERE Date LIKE CONCAT(#{Date},'%')  AND Percent=#{Percent} AND PopID=#{PopID})t  "+
            "</script>")
    int FileSizeByPopIDCount (@Param("Date") String Date, @Param("Percent") String Percent,@Param("PopID") String PopID);
}
